export const exportAudio = (msg: string = 'Hello Word') => {
  const sdk = require('microsoft-cognitiveservices-speech-sdk');
  const readline = require('readline');

  const key = 'e68024063a4f74be08902ac71329082e6'; // 语音资源密钥
  const region = 'EastUS'; // 语音资源地域
  const audioFile = 'YourAudioFile.wav'; // 语音资源文件

  const speechConfig = sdk.SpeechConfig.fromSubscription(key, region);
  const audioConfig = sdk.AudioConfig.fromAudioFileOutput(audioFile);

  // The language of the voice that speaks.
  speechConfig.speechSynthesisVoiceName = 'en-US-JennyNeural';

  // Create the speech synthesizer.
  let synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });

  rl.question(msg, function (text: string) {
    rl.close();
    // Start the synthesizer and wait for a result.
    synthesizer.speakTextAsync(
      text,
      function (result: any) {
        if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
          console.log('synthesis finished.');
        } else {
          console.error(
            'Speech synthesis canceled, ' +
              result.errorDetails +
              '\nDid you set the speech resource key and region values?'
          );
        }
        synthesizer.close();
        synthesizer = null;
      },
      function (err: any) {
        console.trace('err - ' + err);
        synthesizer.close();
        synthesizer = null;
      }
    );
    console.log('Now synthesizing to: ' + audioFile);
  });
};
